<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>7.变速运动</title>
  <style>
    * {
      margin: 0;
      padding: o;
    }

    .main {
      width: 800px;
      margin: 50px auto;

    }

    #wrap {
      width: 800px;
      height: 500px;
      border: solid 2px rebeccapurple;
      position: relative;
      margin-top: 20px;
      margin-left: 100px;
    }

    #move {
      width: 100px;
      height: 100px;
      position: absolute;
      border-radius: 50%;
      background-color: chartreuse;
    }
  </style>
</head>

<body>
  <div class="main">
    <button id="left-button">向左走</button>
    <button id="right-button">向右走</button>

    <div id="wrap">
      <div id="move"></div>
    </div>
  </div>
</body>
<script>
  var leftButton = document.getElementById('left-button')
  var rightButton = document.getElementById('right-button')
  var move = document.getElementById('move')
  var wrap = document.getElementById('wrap')
  var interId
  rightButton.onclick = function (e) {
    move.interId = setInterval(function () {
      if (move.offsetLeft > 700) {
        clearInterval(move.interId)
      } else {
        var step = (700 - move.offsetLeft) / 10
        move.style.left = move.offsetLeft + step + 'px'
      }
    }, 30)
  }
</script>

</html>